package cn.wolfcode.wolf2w.timer;

import cn.wolfcode.wolf2w.domain.UserIdFavors;
import cn.wolfcode.wolf2w.redis.service.IStrategyStatisVORedisService;
import cn.wolfcode.wolf2w.redis.service.IUserIdFavorsRedisService;
import cn.wolfcode.wolf2w.redis.vo.StrategyStatisVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

//@Component
public class RedisDatePersistenceJob {
    @Autowired
    private IStrategyStatisVORedisService strategyStatisVORedisService;
    @Autowired
    private IUserIdFavorsRedisService userIdFavorsRedisService;

    @Scheduled(cron = "0/5 * * * * ? ")
    public void doWork(){
        //从redis中获取所有vo对象
        List<StrategyStatisVO> strategyStatisVOS = strategyStatisVORedisService.findAllStrategyStatisVO();
        //从redis中获取所有userIdFavours对象
        List<UserIdFavors> userIdFavors = userIdFavorsRedisService.findAllUserIdFavors();

        //把所有的vo对象的数据设置回数据库中
        strategyStatisVORedisService.setMongodb(strategyStatisVOS);
        //把所有的UserIdFavors的数据设置回数据库中
        userIdFavorsRedisService.setMongodb(userIdFavors);
    }
}
